package com.bocai.yuweiwangluo.activity;


import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.View.XListView;
import com.bocai.yuweiwangluo.base.BaseActivity;
import com.bocai.yuweiwangluo.bean.MyVenueBean;
import com.bocai.yuweiwangluo.presenter.MyVenueListPresenter;
import com.bocai.yuweiwangluo.viewModel.IMyVenueListView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

/**
 * 我的订场列表界面
 */
public class MyVenueActivity extends BaseActivity implements View.OnClickListener,IMyVenueListView,AdapterView.OnItemClickListener,XListView.IXListViewListener
{

    @ViewInject(R.id.lv_mygame_list)
    XListView lv_mygame_list;
    @ViewInject(R.id.ll_nocotent)
    LinearLayout llnoContent;
    @ViewInject(R.id.ll_refresh)
    LinearLayout llRefresh;
    private int page=1;
    private MyVenueListPresenter myVenueListPresenter;
    @Override
    protected int contentView() {
        return R.layout.activity_mygame;
    }

    @Override
    protected void setData() {
        ViewUtils.inject(this);
        initToolbar("我的订场");
        getMyVenueListPresenter();
        initEvent();
        getMyVenue();
    }

    @Override
    protected void initEvent() {
        llRefresh.setOnClickListener(this);
        lv_mygame_list.setOnItemClickListener(this);
        lv_mygame_list.setPullLoadEnable(true);
        lv_mygame_list.setPullRefreshEnable(true);
        lv_mygame_list.setXListViewListener(this);
    }

    private void getMyVenue() {
        myVenueListPresenter.getMyVenueList();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ll_refresh:
                llRefresh.setVisibility(View.GONE);
                onRefresh();
                break;
        }
    }

    @Override
    public int getmyPage() {
        return page;
    }

    @Override
    public void onLoad() {
        lv_mygame_list.stopRefresh();
        lv_mygame_list.stopLoadMore();
        lv_mygame_list.setRefreshTime("");
    }
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
        try
        {
            MyVenueBean.Data data= (MyVenueBean.Data) parent.getAdapter().getItem(position);
            Intent intent=new Intent(this,VenueBookActivity.class);
            intent.putExtra("id",data.getId());
            intent.putExtra("title",data.getTitle());
            intent.putExtra("content",data.getContent());
            intent.putExtra("local_x",data.getLocal_x());
            intent.putExtra("local_y",data.getLocal_y());
            startActivity(intent);
        }catch (Exception e){}
    }
    @Override
    public XListView getListView() {
        return lv_mygame_list;
    }

    @Override
    public LinearLayout getnoContent() {
        return llnoContent;
    }

    @Override
    public LinearLayout getllRefresh() {
        return llRefresh;
    }


    @Override
    public MyVenueListPresenter getMyVenueListPresenter() {
        myVenueListPresenter=new MyVenueListPresenter(this,this,this);
        return myVenueListPresenter;
    }

    @Override
    public void finishActivity() {
        this.finish();
    }

    @Override
    public void onRefresh() {
        page=1;
        lv_mygame_list.setPullLoadEnable(true);
        myVenueListPresenter.getMyVenueList();
    }

    @Override
    public void onLoadMore() {
        page++;
        myVenueListPresenter.getMyVenueList();
    }

}
